<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('库存修改')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-kucun-edit" th:object="${kucunguanli}">
        <input name="id" th:field="*{id}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label">商品名称
                ：</label>
            <!--                            <div class="col-sm-8">-->
            <!--                                <input name="shangpinbianhao" th:field="*{shangpinbianhao}" class="form-control"-->
            <!--                                       type="text">-->
            <!--                            </div>-->
            <div class="col-sm-8">
                <input id="bianhao" name="shangpinbianhao" th:field="*{shangpinbianhao}"  type="hidden" class="form-control">
                <select th:with="lists=${@shangpinguanliMapper.selectShangpingList()}" th:field="*{shangpinming}"
                        onchange="changevalue(this.value)"
                        name="shangpinming" class="form-control" id="name">
                    <option th:each="type:${lists}"
                            th:text="${type.getShangpinleibie()+'丨'+type.getShangpinguigekuan()+'*'+type.getShangpinguigegao()+'丨'+type.getShangpinkaixiang()}"
                            th:value="${type.getShangpinming()+'丨'+type.getShangpinbianhao()}"></option>
                </select>
                <script>
                    function changevalue(value) {
                        if (value.includes("丨")) {
                            const vlist = value.split("丨");
                            document.getElementById("bianhao").value = vlist[1]
                        }
                    }
                </script>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品库存
                ：</label>
            <div class="col-sm-8">
                <input name="shangpinshuliang" th:field="*{shangpinshuliang}" class="form-control"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品图片
                ：</label>
            <div class="col-sm-8">
                <input type="hidden" name="shangpintupian" th:field="*{shangpintupian}">
                <div class="file-loading">
                    <input class="form-control file-upload" id="shangpintupian" name="file" type="file">
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "cangku/kucun";
    $("#form-kucun-edit").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-kucun-edit').serialize());
        }
    }

    $(".file-upload").each(function (i) {
        var val = $("input[name='" + this.id + "']").val()
        $(this).fileinput({
            'uploadUrl': ctx + 'common/upload',
            initialPreviewAsData: true,
            initialPreview: [val],
            maxFileCount: 1,
            autoReplace: true
        }).on('fileuploaded', function (event, data, previewId, index) {
            $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
        }).on('fileremoved', function (event, id, index) {
            $("input[name='" + event.currentTarget.id + "']").val('')
        })
        $(this).fileinput('_initFileActions');
    });
</script>
</body>
</html>